/*
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Autogenerated file -- DO NOT EDIT!
% component = Messages.component.upcase
#ifndef PANDA_<%= component %>_MESSAGES_GEN_H_
#define PANDA_<%= component %>_MESSAGES_GEN_H_

#include "utils/logger.h"
#include <string_view>

namespace <%= Messages.namespace %> {
%   msg_nums = Messages.messages.map(&:number)
%   msg_first = msg_nums.min
%   msg_last = msg_nums.max
    enum class <%= Messages.enum_name %> : size_t {
        FIRST = <%= msg_first %>,
% Messages.messages.each do |msg|
        <%= msg.name %> = <%= msg.number %>,
% end
        LAST = <%= msg_last %>,
        __UNDEFINED__
    };
}  // namespace <%= Messages.namespace %>

% Messages.messages.each do |msg|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define <%= msg.macro_name %>(<%= msg.args %>) \
% level = msg.level.upcase
% if level != 'DEBUG'
    LOG(<%= level %>, <%= component %>) << <%= msg.stream_ops(true) %>; \
% end
% if msg.message  # may be nil if short message is enough
    LOG(DEBUG, <%= component %>) << <%= msg.stream_ops(false) %>;
% end

% end

namespace <%= Messages.namespace %> {

inline std::string_view <%= Messages.enum_name %>ToString(<%= Messages.enum_name %> num) {
% Messages.messages.each do |msg|
    if (num == <%= Messages.enum_name %>::<%= msg.name %>) { return "<%= msg.name %>"; }
% end
    return "<unknown>";
}

inline bool <%= Messages.enum_name %>IsValid(<%= Messages.enum_name %> num) {
    switch(num) {
% Messages.messages.each do |msg|
        case <%= Messages.enum_name %>::<%= msg.name %>: return true;
% end
        default: return false;
    }
}

inline <%= Messages.enum_name %> StringTo<%= Messages.enum_name %>(std::string_view str) {
% Messages.messages.each do |msg|
    if (str == "<%= msg.name %>") { return <%= Messages.enum_name %>::<%= msg.name %>; }
% end
    if (str == "FIRST") { return <%= Messages.enum_name %>::FIRST; }
    if (str == "LAST") { return <%= Messages.enum_name %>::LAST; }
    return <%= Messages.enum_name %>::__UNDEFINED__;
}

}  // namespace <%= Messages.namespace %>

#endif  // PANDA_<%= component %>_MESSAGES_GEN_H_
